<?php
global $_W;
load()->func('db');
load()->model('setting');
load()->func('communication');
$sql = "
CREATE TABLE IF NOT EXISTS `ims_bsht_tbk_nbnet_setting` (
`id` int(11) NOT NULL,
`uniacid` int(11) DEFAULT '0',
`value` text,
`code` varchar(64) DEFAULT ''
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
";
pdo_run($sql);
$data = array();
$data['ip'] = gethostbyname($_SERVER['SERVER_ADDR']);
$data['domain'] = $_SERVER['HTTP_HOST'];
$setting = setting_load('site');
$data['id'] = isset($setting['site']['key']) ? $setting['site']['key'] : '1';
$data['module'] = 'bsht_tbk';
$url = 'http://oauth.13148687.cn/meepo/api/meepo.php';
$res = ihttp_post($url, $data);
$res = cloud_object_array($res);
$content = $res['content'];
$content = json_decode($content);
$content = cloud_object_array($content);
$setting = $content['setting'];
if (!empty($setting) && $setting['status'] == 1) {
	if (pdo_tableexists('bsht_tbk_nbnet_setting')) {
		$sql = "SELECT * FROM " . tablename('bsht_tbk_nbnet_setting') . " WHERE code = :code";
		$params = array(':code' => 'auth');
		$auth = pdo_fetch($sql, $params);
		$data = array();
		$data['code'] = 'auth';
		$data['value'] = iserializer($setting);
		if (empty($auth)) {
			pdo_insert('bsht_tbk_nbnet_setting', $data);
		} else {
			pdo_update('bsht_tbk_nbnet_setting', $data, array('id' => $auth['id']));
		}
	}
} else {
}
function cloud_object_array($array)
{
	if (is_object($array)) {
		$array = (array)$array;
	}
	if (is_array($array)) {
		foreach ($array as $key => $value) {
			$array[$key] = cloud_object_array($value);
		}
	}
	return $array;
}